*****
*** Authors: Peter Eppinger (PE), Hong Ma (HM)
*** Purpose: Replicate all results in the paper and in Online Appendix B
*** Stata version: 16.1
*** Date: February 20, 2024
***
***** 1. Header
***** 2. Descriptives
***** 3. Regressions: FDI liberalization and foreign ownership
***** 4. Regressions: Ownership restructuring and firm performance
***** 5. Online Appendix B: Additional results
***
****************************************************************************************************************
***** 1. Header

clear all
set linesize 255
cap log close
log using "$results\2_FDI_liberalization_analysis.log", replace

****************************************************************************************************************
***** 2. Descriptives

********************************************************
**** Figure 1: FDI liberalization in Chinese manufacturing, 1998–2007

use "$prepared_data\comb_data_analysis.dta", clear

* generate policy dummy variables
gen res=0 if year<2002 & policy97!=1 
replace res=1 if year<2002 & policy97==1
replace res=0 if year>=2002 & year<2005 & policy02!=1 
replace res=1 if year>=2002 & year<2005 & policy02==1
replace res=0 if year>=2005 & policy05!=1 
replace res=1 if year>=2005 & policy05==1
gen frd=0 if year<2002 & policy97!=0
replace frd=1 if year<2002 & policy97==0
replace frd=0 if year>=2002 & year<2005 & policy02!=0 
replace frd=1 if year>=2002 & year<2005 & policy02==0
replace frd=0 if year>=2005 & policy05!=0 
replace frd=1 if year>=2005 & policy05==0
gen enc=0 if year<2002 & policy97!=3
replace enc=1 if year<2002 & policy97==3
replace enc=0 if year>=2002 & year<2005 & policy02!=3 
replace enc=1 if year>=2002 & year<2005 & policy02==3
replace enc=0 if year>=2005 & policy05!=3 
replace enc=1 if year>=2005 & policy05==3
gen jv=0 if  (year<2002 & no_wfie97==0) |  (year>=2002 & no_wfie02==0)
replace jv=1 if  (year<2002 & no_wfie97==1) |  (year>=2002 & no_wfie02==1)
gen maj=0 if (year<2002 & re_major97==0 & major97==0) |  (year>=2002 & re_major02==0 & major02==0)
replace maj=1 if (year<2002 & (re_major97==1 | major97==1)) |  (year>=2002 & (re_major02==1 | major02==1))

* means (also accounting for multiple restrictions)
egen resfrd=rowtotal(res frd)
recode resfrd (2=1)
egen anyres=rowtotal(res frd maj jv)
recode anyres (2=1) (3=1) (4=1)
sum res frd enc jv maj resfrd anyres if year==2001
sum res frd enc jv maj resfrd anyres if year==2002

* aggregate
collapse (mean) res frd enc jv maj , by(year)

* plot
graph twoway connected res year , color(gs5) lw(medthick) ||  connected frd year ,  color(gs0) ms(X) msize(large) lp(shortdash) lw(medthick)  || connected enc year , color(gs12) ms(Sh) lp(longdash) lw(medthick)  || connected jv year , color(gs9) ms(Dh) lp(longdash_dot) lw(medthick)  || connected maj year , color(gs7) ms(Oh) lp(shortdash_dot) lw(medthick) graphregion(color(white)) legend(order(1 "restricted" 5 "majority requirement" 3 "encouraged" 2 "prohibited" 4 "JV requirement" ) row(2)) ytitle("Share of firms subject to FDI policy") xtitle("") name("fig1gray", replace) xlabel(1998/2007) ylabel(0(0.05)0.2, format(%03.2f))

/* color version
graph twoway connected res year , color(orange) lw(medthick) ||  connected frd year ,  color(red) ms(X) msize(large) lp(shortdash) lw(medthick)  || connected enc year , color(green) ms(Sh) lp(longdash) lw(medthick)  || connected jv year , color(blue) ms(Dh) lp(longdash_dot) lw(medthick)  || connected maj year , color(purple) ms(Oh) lp(shortdash_dot) lw(medthick) graphregion(color(white)) legend(order(1 "restricted" 5 "majority requirement" 3 "encouraged" 2 "prohibited" 4 "JV requirement" ) row(2)) ytitle("Share of firms subject to FDI policy") xtitle("") name("fig1color", replace) xlabel(1998/2007) ylabel(0(0.05)0.2, format(%03.2f))
*/

* export
graph export "$results\Figure1.eps", name(fig1gray) replace font("Times")


********************************************************
**** Figure 2: Prevalence of full foreign ownership among liberalized vs. restricted firms, 1998–2007

use "$prepared_data\comb_data_analysis.dta", clear

* firm counts for note:
unique firm_id if lib1_full01==0
unique firm_id if lib1_full01==1

* plain descriptive regression with std. errors:
reg foreign_full 1.lib1_full01##ib2000.year, cluster(firm_id)

* reduce
keep if lib1_full01!=.

* aggregate
collapse (mean) foreign_full  , by(lib1_full01 year)

* counterfactual: subtract mean difference in 2000 (baseline):
sum foreign_full if year==2000 & lib1_full01==0, mean
local Mnon=r(mean)
sum foreign_full if year==2000 & lib1_full01==1, mean
local Myes=r(mean)
gen foreign_full_minus00=foreign_full+(`Myes'-`Mnon')

* plot
graph twoway  connected foreign_full year if lib1_full01==0, color(gs6) lp(longdash) lw(medthick) ||  connected foreign_full_minus00 year if lib1_full01==0, color(gs12)  ms(Oh) lp(dash_dot) lw(medthick) || connected foreign_full year if lib1_full01==1, color(gs0)  ms(X) msize(large) lw(medthick) graphregion(color(white)) legend(order(3 "liberalized" 1 "still restricted" 2 "counterfactual") row(1)) xlabel(1998/2007) ytitle("Share of fully foreign-owned firms") xtitle("") name("fig2gray", replace)

/* color version
graph twoway  connected foreign_full year if lib1_full01==0, color(blue) lcolor(blue*0.8) lp(longdash) lw(medthick) ||  connected foreign_full_minus00 year if lib1_full01==0, mcolor(eltblue) color(eltblue*0.8)  ms(Oh) lp(dash_dot) lw(medthick) || connected foreign_full year if lib1_full01==1, mcolor(green) lcolor(green*0.7) ms(X) msize(large) lw(medthick) graphregion(color(white)) legend(order(3 "liberalized" 1 "still restricted" 2 "counterfactual") row(1)) xlabel(1998/2007) ytitle("Share of fully foreign-owned firms") xtitle("") name("fig2color", replace)
*/

* export
graph export "$results\Figure2.eps", name("fig2gray") replace font("Times")


****************************************************************************************************************
***** 3. Regressions: FDI liberalization and foreign ownership

********************************************************
**** Table 1: Direct effect of FDI liberalization on foreign ownership

use "$prepared_data\comb_data_analysis.dta", clear

* balancing covariates
global cov_all foreign_share statecoll_share age /* exporter lequity lva ltfp_acf ltfp_index_ind*/ ltfp_index loutput lempl lcap_empl lwage_empl liq_ratio lev_ratio exp_share imp_share newprod_share 

foreach x of varlist $cov_all {
	gen `x'_2000=`x' if year==2000
	bys firm_id: egen `x'_00=max(`x'_2000)
	drop `x'_2000
}

global cov_nofe loutput_00 foreign_share_00 age_00 lwage_empl_00 exp_share_00 imp_share_00 lempl_00
global cov_00 ${cov_nofe} i.cic2

* run unweighted regression to identify relevant sample
qui reghdfe foreign_full  1.lib1_full01##after01 c.TPU_1996#i.year c.AHS_simple98#i.year, cluster(firm_id) absorb(firm_id cic2#year)
gen sample_direct_unw=e(sample)

* compute inverse probability weights
psmatch2 lib1_full01 ${cov_00} if year==2000 & sample_direct_unw==1, logit common
gen double weight_att=cond(lib1_full01,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen ipweight=mean(weight_att)
drop weight_att

* dummy variables for foreign ownership
gen foreign_owned=0 if foreign_share!=.
replace foreign_owned=1 if foreign_share>=0.25 	// Chinese legal threshold for FIE status
gen foreign_majority=0
replace foreign_majority=1 if foreign_share>=0.5 & foreign_share<=1

* IPW regressions
foreach y in foreign_share foreign_full foreign_majority foreign_owned {
	qui reghdfe `y'  1.lib1_full01##after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw=ipweight], cluster(firm_id) absorb(firm_id cic2#year)
	est store DIR_`y'
}

esttab DIR_foreign_share DIR_foreign_full DIR_foreign_majority DIR_foreign_owned, nogap drop(_cons ) star(* 0.1 ** 0.05 *** 0.01) se r2 mtitle nobase noomit
esttab DIR_foreign_share DIR_foreign_full DIR_foreign_majority DIR_foreign_owned using "$results\Table1.csv", replace nogap drop(_cons *year*) star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) se r2 mtitle nobase noomit

* means of dependent variables in 2001 for relative effect sizes (bottom of Table 1)
sum foreign_share foreign_full foreign_majority foreign_owned if e(sample)==1 & year==2001


********************************************************
**** Table B.1 (Online Appendix B): Robustness checks for effect of FDI liberalization on foreign ownership

** define newly encouraged firms:
* zero if not encouraged in 2001 and FDI in the same product will not be encouraged
gen newenc1=0 if year==2001 & (policy97<3) & (policy02<3)
* one if not encouraged in 2001 and same product fully liberalized (no restriction left)
replace newenc1=1 if year==2001 & (policy97<3) & (policy02==3)
bys firm_id: egen newenc01=max(newenc1)
drop newenc1

* baseline replication
qui reghdfe foreign_full  1.lib1_full01##after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw=ipweight], cluster(firm_id) absorb(firm_id cic2#year)
est store R1_full
* control for newly encouraged FDI policy
qui reghdfe foreign_full  1.lib1_full01##after01 1.newenc01##ib2000.year c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw=ipweight], cluster(firm_id) absorb(firm_id cic2#year)
est store R2_full
* 4-digit industry-year FE:
qui reghdfe foreign_full  1.lib1_full01##after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw=ipweight], cluster(firm_id) absorb(firm_id cic_code#year)
est store R3_full
* combined
qui reghdfe foreign_full  1.lib1_full01##after01 1.newenc01##ib2000.year  c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw=ipweight], cluster(firm_id) absorb(firm_id cic_code#year)
est store R4_full

esttab R?_full, nogap star(* 0.1 ** 0.05 *** 0.01) se r2 mtitle nobase noomit keep(1.lib1_full01#1.after01)
esttab R?_full using "$results\TableB1.csv", replace nogap star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) se r2 mtitle nobase noomit keep(1.lib1_full01#1.after01)

********************************************************
**** Table B.2 (Online Appendix B): Effect of FDI liberalization on foreign ownership for alternative FDI policy measures

* Sheng/Yang liberalization dummy by industry
* zero if restricted in 2001 and same product will not be liberalized in 2002
* - initially restricted:
gen lib1_sheng_yang=0 if year<=2001 & (res_sheng_yang==1 | frd_sheng_yang==1)
gen lib1_sheng_yang01=lib1_sheng_yang if year==2001
bys firm_id: egen lib1_sheng_yang2001=max(lib1_sheng_yang01)
* - initial industry code:
gen cic01=cic_code if year==2001
bys firm_id: egen cic2001=max(cic01)
replace lib1_sheng_yang=0 if year>=2002 & (res_sheng_yang==1 | frd_sheng_yang==1) & cic_code==cic2001 & lib1_sheng_yang2001==0 // only for those with unchanged industry codes
replace lib1_sheng_yang=1 if year>=2002 & (res_sheng_yang==0 & frd_sheng_yang==0) & cic_code==cic2001 & lib1_sheng_yang2001==0 // only for those with unchanged industry codes
bys cic_code: egen lib_vsres_sheng_yang=max(lib1_sheng_yang) 
drop lib1_sheng_yang lib1_sheng_yang01 lib1_sheng_yang2001 cic01 cic2001

* code liberalized vs. still restricted industries by Brandt et al measure:
gen lib_vsres_brandt=liberalized_brandt
recode lib_vsres_brandt (2=.) (99=.)

* estimate ipweights
foreach z in sheng_yang brandt {
	qui reghdfe foreign_full  1.lib_vsres_`z'##after01 c.TPU_1996#i.year c.AHS_simple98#i.year, cluster(firm_id) absorb(firm_id cic2#year)
	gen sample_direct_`z'=e(sample)
	psmatch2 lib_vsres_`z' ${cov_00} if year==2000 & sample_direct_`z'==1, logit common
	gen double weight_att=cond(lib_vsres_`z',1,_pscore/(1-_pscore)) if _support==1
	bys firm_id: egen weight_`z'=mean(weight_att)
	drop weight_att
	* without 2-digit sector fixed effects:
	psmatch2 lib_vsres_`z' ${cov_nofe} if year==2000  & sample_direct_`z'==1, logit common
	gen double weight_att=cond(lib_vsres_`z',1,_pscore/(1-_pscore)) if _support==1
	bys firm_id: egen wnofe_`z'=mean(weight_att)
	drop weight_att
	drop sample_direct_`z'
}

* regressions
foreach z in sheng_yang brandt {
	qui reghdfe foreign_full 1.lib_vsres_`z'##after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year , cluster(firm_id) absorb(firm_id cic2#year)
	est store Wnon_`z'
	qui reghdfe foreign_full 1.lib_vsres_`z'##after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw= weight_`z'], cluster(firm_id) absorb(firm_id cic2#year)
	est store Wght_`z'
	qui reghdfe foreign_full 1.lib_vsres_`z'##after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year [pw= wnofe_`z'], cluster(firm_id) absorb(firm_id cic2#year)
	est store Wnof_`z'
}

esttab Wnon_brandt Wnon_sheng_yang Wght_brandt Wght_sheng_yang Wnof_brandt Wnof_sheng_yang , nogap keep(1.lib*after01) star(* 0.1 ** 0.05 *** 0.01) se r2 mtitle nobase noomit
esttab Wnon_brandt Wnon_sheng_yang Wght_brandt Wght_sheng_yang Wnof_brandt Wnof_sheng_yang using "$results\TableB2.csv", replace nogap star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) se r2 mtitle nobase noomit keep(1.lib*after01)


****************************************************************************************************************
***** 4. Regressions: Ownership restructuring and firm performance

use "$prepared_data\comb_data_analysis.dta", clear

* balancing covariates:
global cov_all foreign_share statecoll_share age /* exporter lequity lva ltfp_acf ltfp_index_ind*/ ltfp_index loutput lempl lcap_empl lwage_empl liq_ratio lev_ratio exp_share imp_share newprod_share 

foreach x of varlist $cov_all {
	gen `x'_2000=`x' if year==2000
	bys firm_id: egen `x'_00=max(`x'_2000)
	drop `x'_2000
}

global cov_nofe loutput_00 foreign_share_00 age_00 lwage_empl_00 exp_share_00 imp_share_00 lempl_00
global cov_00 ${cov_nofe} i.cic2

* identify relevant sample

* condition 1: loutput in at least one of the years 2002-07
forvalues x =2/7 {
	gen loutput_200`x'=loutput if year==200`x'
	bys firm_id: egen loutput_0`x'=max(loutput_200`x')
	drop loutput_200`x'
}
egen loutput_any02to07=rowmean(loutput_02 loutput_03 loutput_04 loutput_05 loutput_06 loutput_07)

* condition 2: included in unweighted DiD regression
qui reghdfe loutput 1.after01#1.treated if acq100==1 & AHS_simple98!=. & TPU_1996!=. , absorb(firm_id year#cic_code) vce(cluster firm_id)
est store RC1_att0
cap drop across_sample_unw2
gen across_sample_unw2=e(sample)

* estimate pscores and IP weights
psmatch2 treated ${cov_00} if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=., logit common
gen double weight_att=cond(treated,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen ipweight=mean(weight_att)
rename _support comsupport
drop weight_att
* wisorize weights at 99th percentile
tabstat ipweight, stat(min mean p95 p99 max)
winsor2 ipweight, cuts(0 99) replace

********************************************************
**** Table B.3 (Online Appendix B): Logit estimation of the propensity score and reweighted estimation

* (re)run logit to extract table of marginal effects:
* - full
logit treated ${cov_00} if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=., cluster(firm_id)
gen sample_logit_full=e(sample)
* - also full, but excluding dropped sectors manually (for margins to work)
logit treated ${cov_00} if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=. & sample_logit_full==1, cluster(firm_id)
est store PS_coef
margins, dydx(${cov_nofe}) post
est store PS_ame

* also run weighted logit regression 
* - implicitly excluding dropped sectors and observations off the common support (weights not defined)
logit treated ${cov_00} if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=. & comsupport==1 [pw=ipweight], cluster(firm_id)
est store PSW_coef
margins, dydx(${cov_nofe}) post
est store PSW_ame

esttab PS_coef PS_ame PSW_coef PSW_ame, nogap star(* 0.1 ** 0.05 *** 0.01) se pr2 sca(chi2) order(loutput_00 foreign_share_00 age_00 lempl_00 lwage_empl_00 exp_share_00 imp_share_00) mtitle nobase noomit drop(_cons *cic2)
esttab PS_coef PS_ame PSW_coef PSW_ame using "$results\TableB3.csv", replace nogap star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) se pr2 sca(chi2) order(loutput_00 foreign_share_00 age_00 lempl_00 lwage_empl_00 exp_share_00 imp_share_00) mtitle nobase noomit drop(_cons *cic2)

* examine sector structure - sector 22 largely liberalized (excluded in robustness):
tab cic2 treated if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=.,m
tab cic2 treated if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=. & ipweight!=.,m

********************************************************
**** Figure 3: Effects of reoptimized ownership on firm performance

* IPW regressions for output
* - year dummy interactions
qui reghdfe loutput 1.treated##ib2000.year c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store IPW_loutput_yr
* - simple before-after
qui reghdfe loutput 1.treated#1.after01 c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store IPW_loutput
local y_coef = e(b)[1,1]

* plot
coefplot IPW_loutput_yr, omitted baselevels  keep(1.treated#*) drop(_cons) msize(large) mc(gs8) ciopt(recast(rcap) lstyle(ci) lwidth(medium)) graphregion(color(white)) vert ylabel(-0.2(0.2)0.8, angle(0) format(%03.1f) labsize(medium)) xlabel(, labsize(medium)) coeflabels(1.treated#1998.year = "1998" 1.treated#1999.year = "1999" 1.treated#2000.year = "2000" 1.treated#2001.year = "2001" 1.treated#2002.year = "2002" 1.treated#2003.year = "2003" 1.treated#2004.year = "2004" 1.treated#2005.year = "2005" 1.treated#2006.year = "2006" 1.treated#2007.year = "2007") yline(0, lc(gs12)) name("fig3gray", replace) title("") addplot(scatteri 0 0.5  0 4.5, connect(line) mcolor(none) lw(thick) lp(dash) lcolor(gs4) || scatteri `y_coef' 4.5  `y_coef' 10.5, connect(line) lw(thick) lp(dash) mcolor(none) lcolor(gs4) ) plotregion(margin(small))
/* color version
coefplot IPW_loutput_yr, omitted baselevels  keep(1.treated#*) drop(_cons) msize(large) mc(blue) ciopt(recast(rcap) lstyle(ci) lwidth(medium)) graphregion(color(white)) vert ylabel(-0.2(0.2)0.8, angle(0) format(%03.1f) labsize(medium)) xlabel(, labsize(medium)) coeflabels(1.treated#1998.year = "1998" 1.treated#1999.year = "1999" 1.treated#2000.year = "2000" 1.treated#2001.year = "2001" 1.treated#2002.year = "2002" 1.treated#2003.year = "2003" 1.treated#2004.year = "2004" 1.treated#2005.year = "2005" 1.treated#2006.year = "2006" 1.treated#2007.year = "2007") yline(0, lc(gs12)) name("fig3color", replace) title("") addplot(scatteri 0 0.5  0 4.5, connect(line) mcolor(none) lw(thick) lp(dash) lcolor(red) || scatteri `y_coef' 4.5  `y_coef' 10.5, connect(line) lw(thick) lp(dash) mcolor(none) lcolor(red) ) plotregion(margin(small))
*/

graph export "$results\Figure3.eps", replace name("fig3gray") font("Times")

********************************************************
**** Table 2: Effects of reoptimized ownership on firm outcomes

* IPW regressions for other outcomes

foreach y in loutput ltfp_index lcapital lempl lwage_empl profit_ratio { 
	reghdfe `y' 1.treated#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
	est store IPW_`y'
}

esttab IPW_loutput IPW_ltfp_index IPW_lcapital IPW_lempl IPW_lwage_empl IPW_profit_ratio , se  nogap r2  star(* 0.1 ** 0.05 *** 0.01) drop( _cons  *year*) noomit nobase depvar
esttab IPW_loutput IPW_ltfp_index IPW_lcapital IPW_lempl IPW_lwage_empl IPW_profit_ratio using "$results\Table2.csv", replace se  nogap r2  star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) drop( _cons *year*) noomit nobase depvar

********************************************************
**** Table 3: Effects of reoptimized ownership on other firm outcomes

foreach y in liq_ratio lev_ratio newprod_share exp_share imp_share lkimport { 
	reghdfe `y' 1.treated#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
	est store IPW_`y'
}

esttab IPW_liq_ratio IPW_lev_ratio IPW_newprod_share IPW_exp_share IPW_imp_share IPW_lkimport, se  nogap r2  star(* 0.1 ** 0.05 *** 0.01) drop( _cons  *year*) noomit nobase depvar
esttab IPW_liq_ratio IPW_lev_ratio IPW_newprod_share IPW_exp_share IPW_imp_share IPW_lkimport using "$results\Table3.csv", replace se  nogap r2  star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) drop( _cons *year*) noomit nobase depvar

********************************************************
**** Table B.4 (Online Appendix B): Robustness checks concerning the performance gains from reoptimized ownership

****************************************
** Rambachan and Roth (2023) test mentioned in Section 4.3:
est restore IPW_loutput_yr
matrix list e(b)
honestdid , pre(12/15) post(16/21)  alpha(0.05) mvec(0.5(0.1)1.2) // 95% confidence, maximum deviation = M times maximum observed violation of parallel trends in pre-treatment period

****************************************
** Columns (1)-(2): Robustness with respect to matching procedure: cut-offs for similarity score

*  add policy based on lower cut-offs for similarity score: compare
merge 1:1 firm_id year using "$working_data\policy_nlp\policy_cutoff60.dta"
drop if _merge==2
drop _merge 

merge 1:1 firm_id year using "$working_data\policy_nlp\policy_cutoff70.dta"
drop if _merge==2
drop _merge 

* loop over two alternative cutoffs: 60% and 70% (baseline is 80%)
foreach y in 60 70 {
	* - reconstruct liberalization dummy:
	* -- zero if restricted in 2001 and same product will not be liberalized
	gen lib1=0 if year==2001 & (policy97_cutoff`y'<2 | no_wfie97_cutoff`y'==1 | re_major97_cutoff`y'==1 | major97_cutoff`y'==1) & (policy02_cutoff`y'<2 | no_wfie02_cutoff`y'==1 | re_major02_cutoff`y'==1 | major02_cutoff`y'==1)
	* -- one if restricted in 2001 and same product fully liberalized (no restriction left)
	replace lib1=1 if year==2001 & (policy97_cutoff`y'<2 | no_wfie97_cutoff`y'==1 | re_major97_cutoff`y'==1 | major97_cutoff`y'==1) & (policy02_cutoff`y'==2 | policy02_cutoff`y'==3) & (no_wfie02_cutoff`y'==0 & re_major02_cutoff`y'==0 & major02_cutoff`y'==0)
	bys firm_id: egen lib1_full01_cutoff`y'=max(lib1)
	drop lib1

	* - define never regulated firms:
	cap drop maxpolicy minpolicy maxreg minreg maxeqres maxequity
	egen maxpolicy=rowmax(policy97_cutoff`y' policy02_cutoff`y')
	egen minpolicy=rowmin(policy97_cutoff`y' policy02_cutoff`y')
	bys firm_id: egen maxreg=max(maxpolicy)
	bys firm_id: egen minreg=min(minpolicy)
	tab maxreg minreg
	egen maxeqres=rowmax(no_wfie97_cutoff`y' re_major97_cutoff`y' major97_cutoff`y' no_wfie02_cutoff`y' re_major02_cutoff`y' major02_cutoff`y')
	bys firm_id: egen maxequity=max(maxeqres)
	sum maxpolicy minpolicy maxreg minreg maxeqres maxequity
	gen neverreg_cutoff`y'=0 
	replace neverreg_cutoff`y'=1 if minreg==2 & maxreg==2 & maxequity==0 
	drop maxpolicy minpolicy maxreg minreg maxeqres maxequity
	
	* - Generate the relevant liberalization variable:
	* -- Liberalized:
	gen treated_cutoff`y'=1 if lib1_full01_cutoff`y'==1
	* -- Control never regulated:
	replace treated_cutoff`y'=0 if neverreg_cutoff`y'==1
}

foreach y in 60 70 {
	*- unweighted reg to identify sample
	qui reghdfe loutput 1.treated_cutoff`y'#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 , absorb(firm_id year#cic_code) vce(cluster firm_id)
	gen sample_unw_cutoff`y'=e(sample)
	
	*- pscore estimation
	psmatch2 treated_cutoff`y' ${cov_00} if acq100==1 & year==2000 & sample_unw_cutoff`y'==1  & loutput_any02to07!=., logit common
	gen double weight_att=cond(treated_cutoff`y',1,_pscore/(1-_pscore)) if _support==1
	bys firm_id: egen weight_cutoff`y'=mean(weight_att)
	qui sum weight_cutoff`y',d
	drop weight_att
	
	*- wisorize weights at 99th percentile
	winsor2 weight_cutoff`y', cuts(0 99) replace
	
	*- IPW reg
	qui reghdfe loutput 1.treated_cutoff`y'#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 [pw=weight_cutoff`y'], absorb(firm_id year#cic_code) vce(cluster firm_id)
	est store  ROB_cutoff`y'
}

esttab ROB_cutoff*, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase mtitles

****************************************
** Column (3): Omitting 2001

qui reghdfe loutput 1.treated#1.after01 c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 & year!=2001 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store ROB_omit01

esttab ROB_omit01, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase mtitles

****************************************
** Column (4): Effect relative to 2000

* Liberalization defined based on 2000
* zero if restricted in 2000 and same product will not be liberalized
gen lib1=0 if year==2000 & (policy97<2 | no_wfie97==1 | re_major97==1 | major97==1) & (policy02<2 | no_wfie02==1 | re_major02==1 | major02==1)
* one if restricted in 2000 and same product fully liberalized (no restriction left)
replace lib1=1 if year==2000 & (policy97<2 | no_wfie97==1 | re_major97==1 | major97==1) & (policy02==2 | policy02==3) & (no_wfie02==0 & re_major02==0 & major02==0)
bys firm_id: egen lib1_full00=max(lib1)
drop lib1

* Liberalized:
gen liberalized00=1 if lib1_full00==1
* Control never regulated:
replace liberalized00=0 if neverreg==1
tab liberalized00 year if acq100==1

* after 2000 dummy
gen after00=0 if year<=2000
replace after00=1 if year>2000

*- unweighted reg to identify sample
qui reghdfe loutput 1.liberalized00#1.after00 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 , absorb(firm_id year#cic_code) vce(cluster firm_id)
gen sample_unw_base00=e(sample)
*- pscore estimation
psmatch2 liberalized00 ${cov_00} if acq100==1 & year==2000 & sample_unw_base00==1  & loutput_any02to07!=., logit common
gen double weight_att=cond(liberalized00,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen weight_base00=mean(weight_att)
drop weight_att
*- wisorize weights at 99th percentile
winsor2 weight_base00, cuts(0 99) replace
*- IPW reg
qui reghdfe loutput 1.liberalized00#1.after00 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1  [pw=weight_base00], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store ROB_base00
tab liberalized00 year if e(sample)

esttab ROB_base00, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase mtitles

****************************************
** Column (5): Liberalization defined conditional on products still restricted in later years

** - products produced in 2001 fully liberalized, conditional on currently produced products used to be restricted
gen lib3_full01=lib1_full01
* set to missing in later years 2002-07 if currently produced products were in fact not restricted before 2002
replace lib3_full01=. if year>=2002 & (policy97==2 | policy97==3) & (no_wfie97==0 & no_wfie97==0 & no_wfie97==0)

* Liberalized:
gen lib_cont01=1 if lib3_full01==1
* Control never regulated:
replace lib_cont01=0 if neverreg==1

*- unweighted reg to identify sample
qui reghdfe loutput 1.lib_cont01#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 , absorb(firm_id year#cic_code) vce(cluster firm_id)
gen sample_unw_cont01=e(sample)
*- pscore estimation
psmatch2 lib_cont01 ${cov_00} if acq100==1 & year==2000 & sample_unw_cont01==1  & loutput_any02to07!=., logit common //outcome(loutput_any02to07)
gen double weight_att=cond(lib_cont01,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen weight_cont01=mean(weight_att)
drop weight_att
*- wisorize weights at 99th percentile
winsor2 weight_cont01, cuts(0 99) replace
*- IPW reg
qui reghdfe loutput 1.lib_cont01#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1  [pw=weight_cont01], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store ROB_cont01

esttab  ROB_cont01, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase mtitles

****************************************
** Column (6): Restrict to initially non-zero FO (intensive margin of ownership changes)

* minimum FO share observed before 2001
bys firm_id: egen FO_share_before01=min(foreign_share) if year<2002
bys firm_id: egen min_FO_before2001=min(FO_share_before01)
drop FO_share_before01

*- unweighted reg to identify sample
qui reghdfe loutput 1.treated#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 &  min_FO_before2001>0 & min_FO_before2001<., absorb(firm_id year#cic_code) vce(cluster firm_id)
gen sample_unw_initFO=e(sample)
*- pscore estimation
psmatch2 treated ${cov_00} if acq100==1 & year==2000 & sample_unw_initFO==1  & loutput_any02to07!=., logit common
gen double weight_att=cond(treated,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen weight_initFO=mean(weight_att)
drop weight_att
*- wisorize weights at 99th percentile
winsor2 weight_initFO, cuts(0 99) replace
*- IPW reg
qui reghdfe loutput 1.treated#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 &  min_FO_before2001>0 & min_FO_before2001<. [pw=weight_initFO], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store ROB_initFO

esttab ROB_initFO, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase mtitles

****************************************
** Column (7): Acquisition definition accounting for equity thresholds

*- unweighted reg to identify sample
qui reghdfe loutput 1.treated##ib2000.year  c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100_Equity==1 , absorb(firm_id year#cic_code) vce(cluster firm_id)
cap drop across_sample_unweqt
qui gen across_sample_unweqt=e(sample)
*- pscore estimation
qui psmatch2 treated  ${cov_00}  if acq100_Equity==1 & year==2000 & across_sample_unweqt==1  & loutput_any02to07!=., logit common
gen double weight_att=cond(treated,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen weight_equity=mean(weight_att)
drop weight_att
*- wisorize weights at 99th percentile
winsor2 weight_equity, cuts(0 99) replace
*- IPW reg
qui reghdfe loutput 1.treated#1.after01 c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100_Equity==1 [pw=weight_equity], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store ROB_equitythresh

esttab ROB_equitythresh, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase mtitles

****************************************
** Columns (8)-(9): Vary balancing covariates for IPW

* v1: baseline + more 2000 covariates + tariffs and TPU
global cov1_nofe loutput_00 ltfp_index_00 foreign_share_00 age_00 lwage_empl_00 exp_share_00 imp_share_00 lempl_00 statecoll_share_00 liq_ratio_00 lev_ratio_00 TPU_1996 AHS_simple98
* v2: v1 + lagged output in 1999
gen loutput_1999=loutput if year==1999
bys firm_id: egen loutput_99=max(loutput_1999)
drop loutput_1999
global cov2_nofe loutput_99 loutput_00 ltfp_index_00 foreign_share_00 age_00 lwage_empl_00 exp_share_00 imp_share_00 lempl_00 statecoll_share_00 liq_ratio_00 lev_ratio_00 TPU_1996 AHS_simple98

forvalues n=1/2 {
	global cov`n'_00 ${cov`n'_nofe} i.cic2
}

forvalues n=1/2 {
	*- pscore estimation
	psmatch2 treated ${cov`n'_00} if acq100==1 & year==2000 & across_sample_unw2==1  & loutput_any02to07!=., logit common
	gen double weight_att=cond(treated,1,_pscore/(1-_pscore)) if _support==1
	bys firm_id: egen weight`n'=mean(weight_att)
	drop weight_att
	*- wisorize weights at 99th percentile
	winsor2 weight`n', cuts(0 99) replace
}

*- IPW reg
forvalues n=1/2 {
	qui reghdfe loutput 1.treated#1.after01  c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=weight`n'], absorb(firm_id year#cic_code) vce(cluster firm_id)
	est store ROB_cov`n'
}

esttab ROB_cov*, se  nogap r2 sca(N_clust)  star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase order(1.treated#1.after01) mtitles

****************************************
** Column (10): Exclude paper sector

* Exclude paper sector  (CIC=22, where liberalized firms dominate)

*- unweighted reg to identify sample
qui reghdfe loutput 1.treated#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 &  cic2!=22, absorb(firm_id year#cic_code) vce(cluster firm_id)
gen sample_unw_ex22=e(sample)
*- pscore estimation
psmatch2 treated ${cov_00} if acq100==1 & year==2000 & sample_unw_ex22==1  & loutput_any02to07!=., logit common
gen double weight_att=cond(treated,1,_pscore/(1-_pscore)) if _support==1
bys firm_id: egen weight_ex22=mean(weight_att)
drop weight_att
*- wisorize weights at 99th percentile
winsor2 weight_ex22, cuts(0 99) replace
*- IPW reg
qui reghdfe loutput 1.treated#1.after01 c.TPU_1996#ib2000.year c.AHS_simple98#ib2000.year if acq100==1 &  cic2!=22 [pw=weight_ex22], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store  ROB_ex22

esttab ROB_ex22, se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase order(1.treated#1.after01) mtitles

****************************************
** Summarizing robustness checks in Table B.4: 
esttab ROB_cutoff70 ROB_cutoff60 ROB_omit01 ROB_base00 ROB_cont01 ROB_initFO ROB_equitythresh ROB_cov1 ROB_cov2 ROB_ex22 , se  nogap r2 sca(N_clust) star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year*) noomit nobase order(1.treated#1.after01) mtitles
esttab ROB_cutoff70 ROB_cutoff60 ROB_omit01 ROB_base00 ROB_cont01   using "$results\TableB4.csv", replace se  nogap r2 sca(N_clust) star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) drop( _cons *year*) noomit nobase order(1.treated#1.after01) mtitles
esttab ROB_initFO ROB_equitythresh ROB_cov1 ROB_cov2 ROB_ex22  using "$results\TableB4.csv", append se  nogap r2 sca(N_clust) star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) drop( _cons *year*) noomit nobase order(1.treated#1.after01) mtitles


********************************************************
**** Table 4: Heterogeneous performance effects of reoptimized ownership

des wSL_nber1990 KwL_nber1990 nunn_lib2 exf_klk rd_klk
sum wSL_nber1990 KwL_nber1990 nunn_lib2 exf_klk rd_klk

* identify above-sample-median indicators:
*- capital intensity, based on NBER CES database by industry in 1990
qui sum KwL_nber1990 if acq100==1 & year==2001 & ipweight!=. ,d
gen high_k=1  if KwL_nber1990>=`r(p50)' & KwL_nber1990 <. & year==2001
replace high_k=0  if KwL_nber1990<`r(p50)' & year==2001
bys firm_id: egen high_kint=max(high_k)
drop high_k

*- skill intensity, share of non-production workers in labor force, based on NBER CES database by industry in 1990
cap drop  high_skillint
qui sum wSL_nber1990 if  acq100==1 & year==2001 & ipweight!=. ,d
gen high_s=1  if wSL_nber1990>=`r(p50)' & wSL_nber1990 <. & year==2001
replace high_s=0  if wSL_nber1990<`r(p50)' & year==2001
bys firm_id: egen high_skillint=max(high_s)
drop high_s
tab treated year if acq100==1 & ipweight!=. &  high_skillint==1
tab treated year if acq100==1 & ipweight!=. &  high_skillint==0

*- contract intensity (from Nunn, based on liberal Rauch classification)
qui sum nunn_lib2 if acq100==1 & year==2001 & ipweight!=. ,d
gen high_Nunn=1  if nunn_lib2>=`r(p50)' & nunn_lib2<. & year==2001
replace high_Nunn=0  if nunn_lib2<`r(p50)' & year==2001
bys firm_id: egen hi_Nunn=max(high_Nunn)
drop high_Nunn

* IPW reg: 
*- one by one interacted:
qui reghdfe loutput 1.treated#1.after01 1.after01#1.high_kint 1.treated#1.after01#1.high_kint  c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store Int_K
qui reghdfe loutput 1.treated#1.after01 1.after01#1.high_skillint  1.treated#1.after01#1.high_skillint c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store Int_S
qui reghdfe loutput 1.treated#1.after01 1.after01#1.hi_Nunn 1.treated#1.after01#1.hi_Nunn c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store Int_Nunn

* all three interaction dummies combined
qui reghdfe loutput 1.treated#1.after01 1.after01#1.high_kint 1.after01#1.high_skillint  1.after01#1.hi_Nunn  1.treated#1.after01#1.high_kint 1.treated#1.after01#1.high_skillint 1.treated#1.after01#1.hi_Nunn c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store Int_all3
* interaction dummies combined + interaction terms with financial dependence and R&D intensity
qui reghdfe loutput 1.treated#1.after01 1.after01#1.high_kint 1.after01#1.high_skillint  1.after01#1.hi_Nunn  1.treated#1.after01#1.high_kint 1.treated#1.after01#1.high_skillint 1.treated#1.after01#1.hi_Nunn   1.after01#c.exf_klk 1.treated#1.after01#c.exf_klk  1.after01#c.rd_klk 1.treated#1.after01#c.rd_klk  c.TPU_1996##ib2000.year c.AHS_simple98##ib2000.year if acq100==1 [pw=ipweight], absorb(firm_id year#cic_code) vce(cluster firm_id)
est store Int_all3_plus

esttab Int_K Int_S Int_Nunn Int_all3 Int_all3_plus , se  nogap r2  star(* 0.1 ** 0.05 *** 0.01) drop( _cons *year* 1.after01#1.hi*) noomit nobase mtitles
esttab Int_K Int_S Int_Nunn Int_all3 Int_all3_plus  using "$results\Table4.csv", replace se  nogap r2  star($^c$ 0.1 $^b$ 0.05 $^a$ 0.01) drop( _cons *year* 1.after01#1.hi*)  noomit nobase mtitles


log close
